package com.duobao.controller;

import com.duobao.util.MapMessage;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 用户 Controller
 * Created by haitian.gan on 2017/3/8.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping(value = "/register")
    public MapMessage register(String userName,String passwd){
        // 模拟网页登录时候的校验
        if(StringUtils.isEmpty(userName) || StringUtils.isEmpty(passwd))
            return MapMessage.errorMessage("用户名和密码不能为空!");

        //http://user.game2.cn/register_unionad/tgInfo/2_10010703_0_1_211_30476_5246_2_25_29_524/v/38/from/524/pid/1/cpsgid/211/typefrom/8/usite/524/

        String registerUrl = "http://user.game2.cn/register_unionad/tgInfo" +
                "/2_10010703_0_1_211_30330_5246_2_25_29_524/v/30" +
                "/from/524/pid/1/cpsgid/211/typefrom/8/usite/524/";

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost post = new HttpPost(registerUrl);
        try {
            httpClient.execute(post);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return MapMessage.successMessage().add("","");
    }

}
